@import "../../styles/variables";
@import "../../styles/mixins";

$line-height: 20px;
$checkbox-inner-width: $checkbox-size - 2px;

$checkbox-after-width: $checkbox-inner-width / 4;
$checkbox-after-height: $checkbox-inner-width - $checkbox-after-width - 2px;
$checkbox-after-top: ($line-height - 4px - $checkbox-after-height) / 2;
$checkbox-after-left: ($checkbox-inner-width - $checkbox-after-width) / 2;

label.checkbox {
  display: inline-block;
  position: relative;
  cursor: pointer;
  &:not(.disabled) {
    &:hover {
      &:before {
        background-color: $bg-color;
      }
    }
    &:active {
      &:before {
        background-color: $bg-color;
      }
      &.checked:before,
      &.indeterminate:before {
        border-color: transparent;
        background-color: $primary;
      }
    }
  }
  &:before {
    position: absolute;
    top: 50%;
    display: inline-block;
    width: $checkbox-size;
    height: $checkbox-size;
    border: 1px solid $border-color;
    border-radius: 2px;
    outline: none !important;
    background-color: #fff;
    transition: border 0.2s ease;
    transform: translateY(-50%);
    box-sizing: border-box;
    content: "";
    z-index: 1;
  }
  &.checked:before,
  &.checked:hover:before {
    border-color: transparent;
    background-color: $primary;
  }
  &.checked:after {
    position: absolute;
    top: $checkbox-after-top;
    left: $checkbox-after-left;
    display: block;
    width: $checkbox-after-width;
    height: $checkbox-after-height;
    border-width: 0 1.6px 1.6px 0;
    border-style: solid;
    border-color: #fff;
    transform: rotate(45deg);
    backface-visibility: hidden;
    box-sizing: content-box;
    content: "";
    will-change: transform;
    z-index: 1;
  }
  &.disabled {
    box-shadow: none;
    opacity: 0.5;
    cursor: not-allowed;
  }
  &.indeterminate {
    &:before,
    &:hover:before {
      border-color: transparent;
      background-color: $primary;
    }
    &:after {
      position: absolute;
      top: $checkbox-after-top;
      left: $checkbox-after-left;
      display: block;
      width: 4px;
      height: 8px;
      border: solid #fff;
      border-width: 0 2px 0 0;
      transform: rotate(90deg);
      box-sizing: content-box;
      content: "";
      z-index: 1;
    }
  }
  & span.label-value {
    display: inline-block;
    vertical-align: middle;
    @include TypographyParagraph;
    padding: 0 8px;
    user-select: none;
  }
}

label.checkbox input[type="checkbox"] {
  display: inline-block;
  vertical-align: middle;
  width: $checkbox-size;
  height: $checkbox-size;
  margin: 0;
  opacity: 0;
  outline: none !important;

  &:disabled {
    cursor: not-allowed;
  }
}

.checkbox-group[data-direction="column"] {
  display: flex;
  flex-direction: column;
  label.checkbox {
    width: 100%;
    margin-bottom: $base-margin;
    &:last-child {
      margin-bottom: 0;
    }
  }
}
